package com.lc.user.express.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lc.user.express.R;
import com.lc.user.express.app.AppContext;
import com.lc.user.express.model.CouponModel;

import java.util.List;

/**
 * Created by Administrator on 2016/3/15.
 */
public class CouponAdapter extends BaseListAdapter<CouponModel> {

    public CouponAdapter(Context context, List<CouponModel> data) {
        super(context, data);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        CouponModel model = data.get(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.coupon_list_item, null);
            AppContext.ScaleScreenHelper.loadView((ViewGroup) convertView);
            viewHolder = new ViewHolder();
            viewHolder.tv_accout = (TextView) convertView.findViewById(R.id.tv_accout);
            viewHolder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
            convertView.setTag(viewHolder);

        }
        setContextView(convertView, model);
        return convertView;
    }

    private void setContextView(View convertView, CouponModel model) {
        ViewHolder viewHolder = (ViewHolder) convertView.getTag();
        viewHolder.tv_time.setText(model.getStartTime()+"-"+model.getEndTime());
        viewHolder.tv_accout.setText(model.getAccount());

    }

    private class ViewHolder {
        TextView tv_accout;
        TextView tv_time;
    }
}
